package com.apimarket.dao;

import com.apimarket.entity.Apply;
import com.apimarket.entity.Publish;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public interface ApplyMapper {
    @Select({
            "<script>",
            "select * from application",
            "where 1=1",
            "<when test = 'id != null'> and id = #{id} </when>",
            "</script>"
    })
    List<Apply> queryList(Apply entity);

    @Insert("INSERT INTO `application`(`id`, `set_id`, `dataset_id`,`user_id`, `content`, `pic_urls`, `state`, `examine_id`,`date`,`times`) VALUES (#{id},#{setId},#{datasetId},#{userId},#{content},#{picUrls},#{state},#{examineId},#{date},#{times})")
    int insert(Apply entity);

    @Update("UPDATE `application` SET `id` = #{id}, `set_id` = #{setId}, `user_id` = #{userId}, `content` = #{content}, `pic_urls` = #{picUrls}, `state` =#{state}, `examine_id` = #{examineId} WHERE `id` = #{id}")
    int update(Apply entity);

    @Delete("delete from application where id = #{id}")
    int delete(Integer id);

    List<Apply> findAll(Apply entity);
    @Update("update `application` set state=3,message=#{message} where id=#{id}")
    void applyPass(Apply apply);

    @Update("UPDATE `application` SET `state` = 2,`message`=#{message} where id=#{id}")
    void applyReject(Integer id,String message);

    void updateApply(Apply apply);
    @Select("select * from `application` where dataset_id=#{datasetId} and user_id=#{userId} and state=3")
    List<Apply> getApplyByDatasetAndUser(String datasetId, String userId);




    @Update("update `application` set state=3 where set_id=#{setId}")
    void passSetsById(String setId);

    @Update("update `application` set state=3 where dataset_id=#{setId}")
    void passDatasetById(String setId);

    @Delete("delete from `application` where dataset_id=#{id}")
    void delteByDatasetId(String id);
    @Delete("delete from `application` where set_id=#{id}")
    void deleteByServiceId(String id);
    @Delete("delete from `application` where user_id=#{id}")
    void deleteByUserId(String id);
    @Update("update `application` set state=4 where set_id=#{setId} and state=1")
    void setShiXiaoById(String setId);
    @Update("update `application` set state=4 where dataset_id=#{setId} and state=1")
    void datasetShiXiaoById(String setId);
}
